import React,{useState,useEffect} from 'react'
import AForm from '../../compent/AForm'
import Atable from "../../compent/ABtate"
import { AformConfig, tableColumns, tableData } from "./config/index"
import {emailList} from "../../untils/api"
import axios from "axios"

export default function Eamil() {
    const [pageSizes, setPageSize] = useState(10)
    const [page, setPage] = useState(1)
    const [total, settotal] = useState(0)
    const [data, setData] = useState([])
    const [fromobj, setFeomObj] = useState<object>({})
  
    useEffect(() => {
      getList(page)
    }, [])
    const getList = (page: number, pageSize: number = pageSizes, Fromobj: object = fromobj) => {
      const params = {
        page,
        pageSize: pageSize,
        ...Fromobj
      }
      console.log(params)
      emailList.getEmailList(params).then(res=>{
        console.log(res.data.data[0])
        console.log(res.data.data[1])
        //列表
        setData(res.data.data[0])
        //总数据
        settotal(res.data.data[1])
      })
  
    }
    const onPageSize = (pageNumber: number, pageSize: number) => {
      console.log(pageNumber, pageSize, "从子组件获取")
      setPage(pageNumber)
      setPageSize(pageSize)
      getList(pageNumber, pageSize)
  }
    const submit = (data: any) => {
      console.log(data)
    }
       //评论不通过
       const PassComment = (id: number, pass: boolean) => {
        console.log(id, pass)
  
        axios.patch(`http://49.232.215.167:8101/api/comment/${id}`, { pass }).then(res => {
            console.log(res)
        })
        // comment.PassComment(id,{pass}).then(res=>{
        //     console.log(res)
        //     const msg=`评论${pass?"通过":"未通过"}`
        // })
    }
    //回复评论
    const Recomment = (record: object) => {
        console.log(record)
    }
    //删除评论
    const DeleteComment = (id: number) => {
  
    }
    return (
        <div>
            邮件管理
            <AForm onsubmit={submit} AformConfig={AformConfig}></AForm>
            {/* <Atable columns={tableColumns} data={tableData}></Atable> */}
            <Atable
                total={total}
                page={page}
                pageSize={pageSizes}
                onchange={onPageSize}
                columns={tableColumns(PassComment, Recomment, DeleteComment)}
                data={data}></Atable>
        </div>
    )
}
